<template>
  <div class="merchgroup" :style="'padding-top:'+data.p_t/2+'px; padding-bottom: '+data.p_b/2+'px;'">
    <ul class="merchants" :style="'padding: 0px '+data.p_lr/2+'px;'" v-if='data.list&&data.list.length'>
     <li  v-for="(item, i) in data.list" :key="i" class="item" :style="itemstyle">
        <div :class="'head ' + data.list_type">
          <vimage
            mode="widthFix"
            lazy-load=""
            :src="item.logo"
            alt=""
            class="merch-thumb"
          :style="data.logo_type == 'square' ? 'border-radius: 12px' : 'border-radius: 50%;'"
            draggable="false"
         ></vimage
>
          <div class="content" v-bind:class="data.shownum? '':'nonum'">
            <p class="title" :style="'color: '+data.title_color+'; margin: 0px;'">
              <span class="merchtitle">{{item.name}}</span>
            </p>
            <p v-if="data.shownum" class="subtitle" :style="'color: '+data.num_color">在售商品{{item.commodity_count}}件</p>
          </div>
          <div class="distance" style="justify-content: center;">
            <div class="enter-icon-btn" style="" v-if="data.btn.type == 3">
              <span class="enter-btn-text" :style="'color: '+data.btn.titlecolor1">{{ data.btn.title || '进店看看' }}</span>
              <i class="enter-btn-icon" v-bind:class="data.btn.icon" :style="'color:'+data.btn.icon_color+';background: rgba(0, 0, 0, 0);margin-left:4px'"></i>
            </div>
            <div v-else class="btn" :style="btnstyle">{{ data.btn.title || '进店看看' }}</div>
          </div>
        </div>
        <div class="body" v-if="data.list_type == 'product'">
          <div v-if="item.commodity&&item.commodity.length > 0" :class="'merchant ' + (i == 1 ? 'merchant1' : '')" v-for="(value, i) in item.commodity" :key="i" style="width: 106.333px;">
            <div class="img-box" style="width: 106.333px; height: 106.333px;">
              <vimage :src="value.master" alt="" class="good-img" ></vimage>
              <p v-if="data.show_type == '2'" class="price" style="color: rgb(255, 255, 255); background: rgba(0, 0, 0, 0.5);">￥{{value.sell_price}}</p>
            </div>
            <div class="good-info" v-if="data.show_type == '1'">
              <p class="title" :style="'color:'+data.pr_color">{{value.name}}</p>
              <div class="price"><p class="current-price" :style="'color:'+data.price_color">￥{{value.sell_price}}</p></div>
            </div>
          </div>
          <div class="no-goods" v-if="item.commodity.length == 0">
           <img src="@/assets/images/noprduct.png" class="no-goods-img"/>
          </div>
        </div>
      </li>

    </ul>
     <img style="width: 375px;" v-else src="@/assets/images/nomerch.png"/>
  </div>
</template>

<script>
export default {
  props: {
    data: {
      type: Object,
      default: {}
    }
  },
  computed:{
    itemstyle() {
      return 'background:' + this.data.bg_color + ';border-radius:' + this.data.r_t / 2 + 'px ' + this.data.r_t / 2 + 'px ' + this.data.r_b / 2 + 'px ' + this.data.r_b / 2 + 'px ';
    },
    btnstyle() {
      if (this.data.btn.type == 1) {
        let style =
          'color:' + this.data.btn.titlecolor1 + ';background: rgba(0, 0, 0, 0); border: 1px solid ' + this.data.btn.color + ';border-radius: ' + this.data.btn.rd / 2 + 'px;';
        return style;
      } else {
        let style = 'color: ' + this.data.btn.titlecolor2 + '; background:' + this.data.btn.color + '; border: none; border-radius: ' + this.data.btn.rd / 2 + 'px;';
        return style;
      }

    }
  }
};
</script>

<style lang="scss" scoped>
.merchgroup {
  width: 100%;
  margin: 0 auto;
  // min-height: 200px;
  p {
    margin: 0;
  }
  .merchants {
    margin: 0 auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    .item {
      width: 100%;
      display: flex;
      flex-direction: column;
      border-radius: 6px;
      margin: 0 auto 8px;
      .head {
        display: flex;
        box-sizing: border-box;
        padding: 12px;
        flex-wrap: nowrap;
        .merch-thumb {
          width: 40px;
          height: 40px !important;
          border-radius: 6px;
          margin: auto 9px auto 0;
        }
        .content {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          height: 40px;
          margin: auto 0;
          box-sizing: border-box;
          width: 0;
          flex: 1;
          &.nonum{
            justify-content: center;
          }
          .title {
            font-size: 14px;
            line-height: 20px;
            font-family: PingFang SC;
            font-style: normal;
            font-weight: 600;
            color: #212121;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            display: flex;
            flex-wrap: nowrap;
            .merchtitle {
              display: inline-block;
              flex-grow: 0;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
          .subtitle {
            font-size: 12px;
            line-height: 17px;
            font-family: PingFang SC;
            font-style: normal;
            font-weight: normal;
            color: #969696;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
        .distance {
          height: 40px;
          flex: 0;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .btn {
            font-family: PingFang SC;
            font-style: normal;
            font-weight: normal;
            color: #ff3c29;
            font-size: 12px;
            padding: 0 11px;
            height: 21px;
            border: 1px solid #ff3c29;
            text-align: center;
            display: flex;
            flex-direction: column;
            justify-content: center;
            border-radius: 12px;
            margin: 0 0 auto auto;
            white-space: nowrap;
          }
          .enter-icon-btn {
            font-size: 14px;
            text-align: right;
            display: flex;
            flex-wrap: nowrap;
            white-space: nowrap;
            margin-left: 4px;
          }
          .enter-btn-text,
          .enter-btn-icon {
            display: flex;

            flex-direction: column;

            justify-content: center;
            font-size: 14px;
            height: 14px;
            line-height: 14px;
            color: #ff3c29;
            margin: auto 0;
          }
          .closePosition {
            margin: auto;
          }
        }
        &.list {
          .merch-thumb {
            width: 64px;
            height: 64px !important;
          }
          .content {
            height: 64px;
            padding: 2px 0;
          }
          .distance {
            height: 64px;
          }
        }
      }
      .body {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        padding: 0 12px 12px;
        flex-wrap: nowrap;
        .merchant {
          width: 106px;
          display: flex;
          flex-direction: column;
          &.merchant1 {
            margin: 0 4px;
          }
          .img-box {
            width: 106px;
            height: 106px;
            overflow: hidden;
            border-radius: 6px;
            position: relative;
            margin-bottom: 4px;
            .good-img {
              width: 100%;
              height: 100%;
            }
            .price {
              position: absolute;
              left: 0;
              bottom: 0;
              height: 17px;
              text-align: center;
              background: rgba(0, 0, 0, 0.5);
              border-radius: 0 2px 0 0;
              padding: 0 4px;
              color: #fff;
              font-size: 12px;
              display: flex;
              font-weight: 300;
              flex-direction: column;
              justify-content: center;
            }
          }
          .good-info {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            flex: 1;
            .title {
              width: 100%;
              font-family: PingFang SC;
              font-style: normal;
              font-weight: normal;
              font-size: 14px;
              line-height: 20px;
              max-height: 40px;
              color: #212121;
              margin-bottom: 4px;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
            .price {
              display: flex;
              flex-wrap: nowrap;
            }
            .current-price {
              font-family: PingFang SC;
              font-style: normal;
              font-weight: 700;
              font-size: 12px;
              line-height: 17px;
              display: flex;
              align-items: center;
              color: #ff3c29;
              margin: auto 4px auto 0;
            }
          }
        }
        .no-goods {
          display: flex;
          width: 100%;
          justify-content: center;
          flex-direction: column;
          .no-goods-img {
            width: 100%;
            // height: 70px;
            // margin: 8px auto;
          }
          .no-goods-tip {
            font-family: PingFang SC;
            font-style: normal;
            font-weight: normal;
            font-size: 12px;
            line-height: 17px;
            display: flex;
            align-items: center;
            margin: 0 auto 6px;
            color: #969696;
          }
        }
      }
    }
  }
}
</style>
